package integral_record

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/integral_record"
    integral_recordReq "github.com/flipped-aurora/gin-vue-admin/server/model/integral_record/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type IntegralRecordsApi struct {}



// CreateIntegralRecords 创建integralRecords表
// @Tags IntegralRecords
// @Summary 创建integralRecords表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body integral_record.IntegralRecords true "创建integralRecords表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /integralRecords/createIntegralRecords [post]
func (integralRecordsApi *IntegralRecordsApi) CreateIntegralRecords(c *gin.Context) {
	var integralRecords integral_record.IntegralRecords
	err := c.ShouldBindJSON(&integralRecords)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = integralRecordsService.CreateIntegralRecords(&integralRecords)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteIntegralRecords 删除integralRecords表
// @Tags IntegralRecords
// @Summary 删除integralRecords表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body integral_record.IntegralRecords true "删除integralRecords表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /integralRecords/deleteIntegralRecords [delete]
func (integralRecordsApi *IntegralRecordsApi) DeleteIntegralRecords(c *gin.Context) {
	id := c.Query("id")
	err := integralRecordsService.DeleteIntegralRecords(id)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteIntegralRecordsByIds 批量删除integralRecords表
// @Tags IntegralRecords
// @Summary 批量删除integralRecords表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /integralRecords/deleteIntegralRecordsByIds [delete]
func (integralRecordsApi *IntegralRecordsApi) DeleteIntegralRecordsByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	err := integralRecordsService.DeleteIntegralRecordsByIds(ids)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateIntegralRecords 更新integralRecords表
// @Tags IntegralRecords
// @Summary 更新integralRecords表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body integral_record.IntegralRecords true "更新integralRecords表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /integralRecords/updateIntegralRecords [put]
func (integralRecordsApi *IntegralRecordsApi) UpdateIntegralRecords(c *gin.Context) {
	var integralRecords integral_record.IntegralRecords
	err := c.ShouldBindJSON(&integralRecords)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = integralRecordsService.UpdateIntegralRecords(integralRecords)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindIntegralRecords 用id查询integralRecords表
// @Tags IntegralRecords
// @Summary 用id查询integralRecords表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query integral_record.IntegralRecords true "用id查询integralRecords表"
// @Success 200 {object} response.Response{data=integral_record.IntegralRecords,msg=string} "查询成功"
// @Router /integralRecords/findIntegralRecords [get]
func (integralRecordsApi *IntegralRecordsApi) FindIntegralRecords(c *gin.Context) {
	id := c.Query("id")
	reintegralRecords, err := integralRecordsService.GetIntegralRecords(id)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(reintegralRecords, c)
}
// GetIntegralRecordsList 分页获取integralRecords表列表
// @Tags IntegralRecords
// @Summary 分页获取integralRecords表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query integral_recordReq.IntegralRecordsSearch true "分页获取integralRecords表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /integralRecords/getIntegralRecordsList [get]
func (integralRecordsApi *IntegralRecordsApi) GetIntegralRecordsList(c *gin.Context) {
	var pageInfo integral_recordReq.IntegralRecordsSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := integralRecordsService.GetIntegralRecordsInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetIntegralRecordsPublic 不需要鉴权的integralRecords表接口
// @Tags IntegralRecords
// @Summary 不需要鉴权的integralRecords表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /integralRecords/getIntegralRecordsPublic [get]
func (integralRecordsApi *IntegralRecordsApi) GetIntegralRecordsPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    integralRecordsService.GetIntegralRecordsPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的integralRecords表接口信息",
    }, "获取成功", c)
}
